//
//  HBRequest.m
//  HeartBeat
//
//  Created by karong on 2023/8/23.
//

#import "HBRequest.h"
#import "HBChannelModel.h"
#import "HBChannelItemModel.h"
#import "HBHistoryModel.h"
#import "HBSignModel.h"
#import "HBTaskModel.h"
#import "HBCategoryModel.h"
#import "HBFeedbackCell.h"
#import "HBGoodsModel.h"
#import "HBPayCoinModel.h"

@implementation HBRequest
+ (void)获取启动配置 {
    NSString * url = API_HEARTBEAT_START_CONFIG;
    NSDictionary * parameters = @{};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        HBStartConfig * startConfig = [HBStartConfig mj_objectWithKeyValues:responseDict];
        appConfig.startConfig = startConfig;
    } failure:^(NSURLResponse * _Nonnull response, NSError * _Nonnull error, id  _Nonnull responseObject) {
        
    }];
}

+ (void)loginWithSuccess:(回调一个对象)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_LOGIN;
    NSString * language = [[NSLocale preferredLanguages] firstObject];
    NSDictionary * parameters = @{@"token":KEmptyStr(appUserCenter.qtoken),
                                  @"device_lang":KEmptyStr(language)
    };
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        HBUserCenterModel * userCenterModel = [HBUserCenterModel mj_objectWithKeyValues:responseDict];
        [appUserCenter logIn:userCenterModel];
        success(userCenterModel);
    } failure:failed];
}

+ (void)loginLineWithAccess_token:(NSString *)access_token success:(回调一个对象)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_LINE_LOGIN;
    NSString * language = [[NSLocale preferredLanguages] firstObject];
    NSDictionary * parameters = @{@"access_token":KEmptyStr(access_token)
    };
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        HBUserCenterModel * userCenterModel = [HBUserCenterModel mj_objectWithKeyValues:responseDict];
        [appUserCenter logIn:userCenterModel];
        success(userCenterModel);
    } failure:failed];
}

+ (void)uploadImage:(UIImage *)image success:(回调一个字符串)success failed:(失败回调)failed {
    NSString *url = API_HEARTBEAT_UPLOAD_IMAGE;
    NSString *fileStr = [@"Q5y9" md5String];
    NSDictionary * parameters = @{@"path":@"dialog",
                                  @"sign":fileStr
    };
    NSData *data =UIImageJPEGRepresentation(image, 0.6) ;// UIImageJPEGRepresentation([UIImage fixOrientationImage:image], 0.8);
    if (data == nil) {
        data = UIImagePNGRepresentation(image);
    }
    if (!data) {
        return;
    }
    // 設置時間格式
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyyMMddHHmmss"];
    NSString *dateString = [formatter stringFromDate:[NSDate date]];
    NSString *fileName = [NSString stringWithFormat:@"%@.jpg", dateString];
    [self postWithURLString:url parameters:parameters fileDatas:@[data] fileNames:@[fileName] success:^(NSDictionary *responseDict) {
        NSDictionary * date = responseDict[@"data"];
        NSString *imageURLString = date[@"url"];
        if (KIsNullOrEmpty(imageURLString)) {
            [HBToast simple:WSLocalized(@"圖片上傳失敗，請重新選擇")];
        }
        else {
            success(imageURLString);
        }
    } failure:failed];
}

+ (void)getUserInfoWithUser_id:(NSInteger)user_id success:(回调一个对象)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_USER_INFO;
    NSDictionary * parameters = @{@"user_id":@(user_id)};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        HBUserCenterModel * userCenter = [HBUserCenterModel mj_objectWithKeyValues:responseDict];
        success(userCenter);
    } failure:failed];
}

+ (void)loadDiscoverChannelSuccess:(回调一个数组)success
                            failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_CHANNEL;
    NSDictionary * parameters = @{};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        NSMutableArray * channelList = [HBChannelModel mj_objectArrayWithKeyValuesArray:responseDict[@"items"]];
        success(channelList);
    } failure:failed];
}

+ (void)loadChannelItemWithChannelId:(NSInteger)channelId channelType:(NSInteger)channelType success:(回调一个数组)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_CHANNEL_CONFIG;
    NSDictionary * parameters = @{@"channel_id":@(channelId),
                                  @"channel_type":@(channelType)};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        NSDictionary *typeDict = @{@(HBChannelConfigType1): @"HBNovelModel", /// 横向水平滑动
                                   @(HBChannelConfigType2): @"HBNovelModel", /// 横向布局一行2个
                                   @(HBChannelConfigType3): @"HBItemModel", /// Banner(656*300)
                                   @(HBChannelConfigType4): @"HBItemModel", /// 运营位小喇叭
                                   @(HBChannelConfigType5): @"HBNovelModel", /// 排行榜
        };
        NSArray * array = [HBChannelItemModel mj_objectArrayWithKeyValuesArray:responseDict[@"items"]];
        NSMutableArray * channelItemArray = [NSMutableArray new];
        for (HBChannelItemModel * channelItemModel in array) {
            if (channelItemModel.items.count > 0) {
                NSString *className = typeDict[@(channelItemModel.style)];
                if (className.length == 0) {
                    continue;
                }
                Class class = NSClassFromString(className);
                channelItemModel.items = [class mj_objectArrayWithKeyValuesArray:channelItemModel.items];
                [channelItemArray addObject:channelItemModel];
            }
            if (channelItemModel.style == HBChannelConfigType5 && (channelItemModel.rank_list.most_favors.count > 0 || channelItemModel.rank_list.most_read.count > 0 || channelItemModel.rank_list.newest.count > 0)) {
                [channelItemArray addObject:channelItemModel];
            }
            if (channelItemModel.style == HBChannelConfigType3) {
                for (HBItemModel * itemModel in channelItemModel.items) {
                    [HBEvenManager event:@"Discovery_banner" evenLogType:(HBEvenLogType_Show) attributes:@{@"banner_id":SF(@"%ld", (long)itemModel.position_id)}];
                }
            }
            if (channelItemModel.is_more) {
                [HBEvenManager event:@"view_more" evenLogType:(HBEvenLogType_Show)
                          attributes:@{@"Module_id":SF(@"%ld", (long)channelItemModel.id)}];
            }
        }
        success(channelItemArray);
    } failure:failed];
}

+ (void)loadForYouListWithChannel_type:(NSInteger)channel_type page:(NSInteger)page success:(回调一个数组)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_FOR_YOU_CHOICE;
    NSDictionary * parameters = @{@"channel_type":@(channel_type),
                                  @"page":@(page),
                                  @"limit":@(10)
    };
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        NSMutableArray * array = [HBNovelModel mj_objectArrayWithKeyValuesArray:responseDict[@"items"]];
        success(array);
    } failure:failed];
}

+ (void)loadCategoryWithChannel_type:(NSInteger)channel_type success:(回调一个对象)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_CATEGORY;
    NSDictionary * parameters = @{@"channel_type":@(channel_type)};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        HBCategoryModel * categoryModel = [HBCategoryModel mj_objectWithKeyValues:responseDict];
        success(categoryModel);
    } failure:failed];
}

+ (void)loadCategoryListWithCategoryDic:(NSDictionary *)categoryDic page:(NSInteger)page success:(回调一个数组)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_CATEGORY_LIST;
    NSMutableDictionary * parameters = [[NSMutableDictionary alloc]initWithDictionary:categoryDic];
    parameters[@"page"] = @(page);
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        NSMutableArray * array = [HBNovelModel mj_objectArrayWithKeyValuesArray:responseDict[@"items"]];
        success(array);
    } failure:failed];
}

+ (void)loadHotSearchSuccess:(回调一个数组)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_SEARCH_HOT;
    NSDictionary * parameters = @{};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        NSMutableArray * array = [HBNovelModel mj_objectArrayWithKeyValuesArray:responseDict[@"items"]];
        success(array);
    } failure:failed];
}

+ (void)loadSearchWithKeyWord:(NSString *)keyword page:(NSInteger)page success:(回调一个数组)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_BOOK_SEARCH;
    NSDictionary * parameters = @{@"keyword":KEmptyStr(keyword),
                                  @"page":@(page),
                                  @"limit":@(10)
    };
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        NSMutableArray * array = [HBNovelModel mj_objectArrayWithKeyValuesArray:responseDict[@"items"]];
        success(array);
    } failure:failed];
}

+ (void)loadRankWithSort_type:(NSInteger)sort_type channel_type:(NSInteger)channel_type page:(NSInteger)page success:(nonnull 回调一个数组)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_RANK_MORE;
    NSDictionary * parameters = @{@"sort_type":@(sort_type),
                                  @"channel_type":@(channel_type),
                                  @"page":@(page),
                                  @"limit":@(10)
    };
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        NSMutableArray * array = [HBNovelModel mj_objectArrayWithKeyValuesArray:responseDict[@"items"]];
        success(array);
    } failure:failed];
}

+ (void)loadNewestWithKeyPage:(NSInteger)page success:(nonnull 回调一个数组)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_NEWEST_MORE;
    NSDictionary * parameters = @{@"page":@(page),
                                  @"limit":@(10)
    };
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        NSMutableArray * array = [HBNovelModel mj_objectArrayWithKeyValuesArray:responseDict[@"items"]];
        success(array);
    } failure:failed];
}

+ (void)loadNovelDetailWithId:(NSInteger)novelId success:(回调一个对象)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_NOVEL_DETAIL;
    NSDictionary * parameters = @{@"id":@(novelId)};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        HBNovelModel * novelModel = [[HBNovelModel alloc]mj_setKeyValues:responseDict];
        success(novelModel);
    } failure:failed];
}

+ (void)loadChapterDetailWithChapter_id:(NSInteger)chapter_id success:(回调一个对象)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_NOVEL_CHAPTER_DETAIL;
    NSDictionary * parameters = @{@"id":@(chapter_id)};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        HBChapterModel * chapter = [HBChapterModel mj_objectWithKeyValues:responseDict];
        success(chapter);
    } failure:failed];
}

+ (void)addBookshelfWithAddArray:(NSArray *)addArray success:(空回调)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_BOOKSHELF_ADD;
    NSMutableString * ids = [NSMutableString new];
    NSMutableString * chapter_ids = [NSMutableString new];
    for (HBNovelModel * novel in addArray) {
        [ids appendString:SF(@"%ld,", (long)novel.book_id)];
        if ([novel isKindOfClass:NSClassFromString(@"HBHistoryModel")]) {
            [chapter_ids appendString:SF(@"%ld,", (long)novel.chapter_id)];
        }
        else {
            [chapter_ids appendString:SF(@"%ld,", (long)(novel.had_read?novel.chapter_id:0))];
        }
        
    }
    NSMutableDictionary * parameters = [NSMutableDictionary new];
    parameters[@"book_ids"] = ids;
    parameters[@"chapter_ids"] = chapter_ids;
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        [[NSNotificationCenter defaultCenter]postNotificationName:HBRefreshFollowNotification object:nil];
        success();
    } failure:failed];
}

+ (void)loadFollowListWithPage:(NSInteger)page success:(回调一个数组)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_BOOKSHELF;
    NSDictionary * parameters = @{@"page":@(page),
                                  @"limit":@(10)};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        NSMutableArray * bookList = [HBNovelModel mj_objectArrayWithKeyValuesArray:responseDict[@"items"]];
        success(bookList);
    } failure:failed];
}

+ (void)delBookshelfWithDelArray:(NSArray *)delArray success:(空回调)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_BOOKSHELF_DEL;
    NSMutableString * ids = [NSMutableString new];
    for (HBNovelModel * novel in delArray) {
        if (ids.length > 0) {
            [ids appendString:@","];
        }
        [ids appendString:SF(@"%ld", (long)novel.book_id)];
    }
    NSDictionary * parameters = @{@"book_ids":ids};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        [[NSNotificationCenter defaultCenter]postNotificationName:HBRefreshFollowNotification object:nil];
        success();
    } failure:failed];
}

+ (void)loadHistoryListWithPage:(NSInteger)page success:(回调一个数组)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_BOOK_HISTORY;
    NSDictionary * parameters = @{@"page":@(page),
                                  @"limit":@(10)};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        NSMutableArray * array = [HBHistoryModel mj_objectArrayWithKeyValuesArray:responseDict[@"items"]];
        success(array);
    } failure:failed];
}

+ (void)delHistoryWithDelArray:(NSArray *)delArray success:(空回调)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_BOOK_HISTORY_DEL;
    NSMutableString * ids = [NSMutableString new];
    for (HBHistoryModel * history in delArray) {
        [ids appendString:SF(@"%ld,", (long)history.id)];
    }
    NSDictionary * parameters = @{@"ids":ids};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        success();
    } failure:failed];
}

+ (void)loadTaskListWithSuccess:(回调一个对象)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_TASK_LIST;
    NSDictionary * parameters = @{};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        HBTask * task = [HBTask mj_objectWithKeyValues:responseDict];
        success(task);
    } failure:failed];
    
}

+ (void)loadSignListWithSuccess:(回调一个对象)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_USER_SIGN_LIST;
    NSDictionary * parameters = @{};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        HBSign * sign = [HBSign mj_objectWithKeyValues:responseDict];
        success(sign);
    } failure:failed];
}

+ (void)signWithSuccess:(空回调)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_USER_SIGN;
    NSDictionary * parameters = @{};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        [appUserCenter getUserInfoRequest];
        success();
    } failure:failed];
}

+ (void)receiveWithTask_id:(NSInteger)task_id success:(空回调)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_TASK_GETREWARD;
    NSDictionary * parameters = @{@"task_id":@(task_id)};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        [appUserCenter getUserInfoRequest];
        success();
    } failure:failed];
}

+ (void)loadNovelChapterListWithBookId:(NSInteger)bookId sort_type:(NSInteger)sort_type page:(NSInteger)page success:(回调一个对象)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_NOVEL_CHAPTER_LIST;
    NSDictionary * parameters = @{@"book_id":@(bookId),
                                  @"sort_type":@(sort_type),
                                  @"page":@(page),
                                  @"limit":@(10)
    };
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        HBChaptersModel * chaptersModel = [[HBChaptersModel alloc]mj_setKeyValues:responseDict];
        success(chaptersModel);
    } failure:failed];
}

+ (void)editUserInfoWithField:(NSString *)field stringValue:(NSString *)value success:(空回调)success failed:(失败回调)failed {
    NSDictionary * parameters = @{@"field":KEmptyStr(field),
                                  @"value":KEmptyStr(value)
    };
    [self editUserInfoWithParameters:parameters success:success failed:failed];
}

+ (void)editUserInfoWithField:(NSString *)field integerValue:(NSInteger)value success:(空回调)success failed:(失败回调)failed {
    NSDictionary * parameters = @{@"field":KEmptyStr(field),
                                  @"value":@(value)
    };
    [self editUserInfoWithParameters:parameters success:success failed:failed];
}

+ (void)editUserInfoWithParameters:(NSDictionary *)parameters success:(空回调)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_USER_EDIT;
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        success();
    } failure:failed];
}

+ (void)loadFeedbackTypeWithSuccess:(回调一个数组)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_FEEDBACK_TYPE;
    NSDictionary * parameters = @{};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        NSArray * array = [GRFeedbackType mj_objectArrayWithKeyValuesArray:responseDict[@"items"]];
        success(array);
    } failure:failed];
}

+ (void)submitFeedbackWithOpinion:(NSString *)opinion type:(NSInteger)type images:(NSString *)images success:(空回调)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_FEEDBACK_SUBMIT;
    NSDictionary * parameters = @{@"opinion":KEmptyStr(opinion),
                                  @"type":@(type),
                                  @"images":KEmptyStr(images),
                                  @"user_id":@(appUserCenter.id)
    };
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        success();
    } failure:failed];
}

+ (void)delUserWithSuccess:(空回调)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_USER_DEL;
    NSDictionary * parameters = @{};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        [appUserCenter logOut];
        success();
    } failure:failed];
}

+ (void)loadGoodsListWithGoods_type:(NSInteger)goods_type success:(回调一个数组)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_GOODS_LIST;
    NSDictionary * parameters = @{@"goods_type":@(goods_type)};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        NSArray * array = [HBGoodsModel mj_objectArrayWithKeyValuesArray:responseDict[@"items"]];
        NSMutableArray * mutArray = [[NSMutableArray alloc]initWithArray:array];
        for (HBGoodsModel * goods in mutArray) {
            if (goods.is_first) {
                goods.vip_activity_tag = WSLocalized(@"首充優惠");
                if ([mutArray indexOfObject:goods] > 0) {
                    [mutArray removeObject:goods];
                    [mutArray insertObject:goods atIndex:0];
                }
                break;
            }
        }
        success(mutArray);
    } failure:failed];
}

+ (void)orderValidWithOrder_no:(NSString *)order_no receipt_data:(NSString *)receipt_data success:(空回调)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_ORDER_VALID;
    NSDictionary * parameters = @{@"order_no":KEmptyStr(order_no),
                                  @"receipt_data":KEmptyStr(receipt_data)};
    [self postAppleOrderWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        [appUserCenter getUserInfoRequest];
        success();
    } failure:failed];
}

+ (void)orderCreatWithGoods_id:(NSInteger )goods_id novel_id:(NSInteger)novel_id chapter_id:(NSInteger)chapter_id success:(回调一个字符串)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_ORDER_CREAT;
    NSMutableDictionary * parameters = [NSMutableDictionary new];
    parameters[@"goods_id"] = @(goods_id);
    parameters[@"pay_type"] = @(2);
    (chapter_id>0)?parameters[@"chapter_id"] = @(chapter_id):nil;
    (novel_id>0)?parameters[@"book_id"] = @(novel_id):nil;
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        success(responseDict[@"order_no"]);
    } failure:failed];
}

+ (void)loadPayListWithChapter_id:(NSInteger)chapter_id success:(回调一个对象)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_NOVEL_CHAPTER_CANBUY;
    NSDictionary * parameters = @{@"chapter_id":@(chapter_id)};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        HBPayModel * payModel = [HBPayModel mj_objectWithKeyValues:responseDict];
        success(payModel);
    } failure:failed];
}

+ (void)payChapterWithChapter_id:(NSInteger)chapter_id success:(空回调)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_CHAPTER_PAY;
    NSDictionary * parameters = @{@"chapter_id":@(chapter_id),
    };
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        [appUserCenter getUserInfoRequest];
        success();
    } failure:failed];
}

+ (void)packageWithChapter_id:(NSInteger)chapter_id num:(NSInteger)num success:(空回调)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_CHAPTER_PACKAGE_PAY;
    NSDictionary * parameters = @{@"chapter_id":@(chapter_id),
                                  @"num":@(num),
    };
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        [appUserCenter getUserInfoRequest];
        success();
    } failure:failed];
}

+ (void)addReadLogWithChapter_id:(NSInteger)chapter_id success:(空回调)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_CHAPTER_READLOG;
    NSDictionary * parameters = @{@"id":@(chapter_id)};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        [[NSNotificationCenter defaultCenter]postNotificationName:HBRefreshBookInfoNotification object:nil];
        [[NSNotificationCenter defaultCenter]postNotificationName:HBRefreshFollowNotification object:nil];
        success();
    } failure:failed];
}

+ (void)addScoreWithNovel_Id:(NSInteger)novel_Id score:(NSInteger)score success:(空回调)success failed:(失败回调)failed {
    NSString * url = API_HEARTBEAT_NOVEL_SCORE;
    NSDictionary * parameters = @{@"book_id":@(novel_Id),
                                  @"score":@(score),
                                  @"content":@"  "
    };
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        [[NSNotificationCenter defaultCenter]postNotificationName:HBRefreshBookInfoNotification object:nil];
        success();
    } failure:failed];
}
@end
